﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Exhibition.RenderTemplete.Controls;
using Exhibition.Common.Helper;
using Exhibition.Dao.ViewModel;
using Exhibition.Service;

namespace Exhibition.Manage
{
    public partial class NavDetail : BaseAdminPage
    {
        NavModel model = new NavModel();
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                hfId.Value = reqID.ToString();
                BindDrop();
                GetNav();
            }

        }

        private void BindDrop()
        {
            new NavTreeList().DropDownTree.Bind(drpParent, "", "0");
            drpParent.Items.Insert(0,new ListItem("作为一级栏目","0"));
        }

        private void GetNav()
        {
            model = CenterService.navService.GetOneById(reqID);
            if (model != null)
            {

                //栏目名称
                txtNavName.Value = model.NavName;

                //栏目英文
                //txtNavEName.Value = model.NavEName.ToString();

                //描述
                txtNavDesc.Text = model.NavDesc;
                txtENavDesc.Text = model.NavEDesc;
                //是否显示
                rdoUsed.SelectedValue = model.IsShow.ToString();
                rdoSingle.SelectedValue = model.IsSingle.ToString();
                drpParent.SelectedValue = model.ParentID.ToString();
                //父ID
                //txtParentID.Value = model.ParentID.ToString();

                //创建时间
                //txtCreateTime.Value = model.CreateTime.ToString();

                ////Seo标题
                //txtSeoTitile.Value = model.SeoTitile.ToString();

                ////Seo英文标题
                //txtSeoEtitle.Value = model.SeoEtitle.ToString();

                ////SeoKey
                //txtSeoKey.Value = model.SeoKey.ToString();

                ////SeoEkey
                //txtSeoEkey.Value = model.SeoEkey.ToString();

                ////SeoDesc
                //txtSeoDesc.Value = model.SeoDesc.ToString();

                ////SeoEDesc
                //txtSeoEDesc.Value = model.SeoEDesc.ToString();

                //排序
                txtOrderId.Value = model.OrderId.ToString();

                //SiteID
                //txtSiteID.Value = model.SiteID.ToString();

                ////
                //txtListTemplate.Value = model.ListTemplate.ToString();

                ////
                //txtListETemplate.Value = model.ListETemplate.ToString();

                ////
                //txtContentTemplate.Value = model.ContentTemplate.ToString();

                ////
                //txtContentETemplate.Value = model.ContentETemplate.ToString();

            }
        }

        /// <summary>
        /// 保存一条数据
        /// <summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = string.IsNullOrEmpty(hfId.Value)||hfId.Value=="0" ? new NavModel() : CenterService.navService.GetOneById(Convert.ToInt32(hfId.Value));
            //栏目名称
            model.NavName = txtNavName.Value;

            //栏目英文
             model.NavEName=txtNavEName.Value;

            //描述
            model.NavDesc = txtNavDesc.Text;

            //是否显示
            model.IsShow = Convert.ToInt32(rdoUsed.SelectedValue);

            model.IsSingle = Convert.ToInt32(rdoSingle.SelectedValue);
            //父ID
            model.ParentID = Convert.ToInt32(drpParent.SelectedValue);

            model.SiteID = CurrentSite.Id;
            //创建时间
            model.CreateTime = DateTime.Now;
            model.NavEDesc = txtENavDesc.Text;
            ////Seo标题
            //model.SeoTitile = txtSeoTitile.Value;

            ////Seo英文标题
            //model.SeoEtitle = txtSeoEtitle.Value;

            ////SeoKey
            //model.SeoKey = txtSeoKey.Value;

            ////SeoEkey
            //model.SeoEkey = txtSeoEkey.Value;

            ////SeoDesc
            //model.SeoDesc = txtSeoDesc.Value;

            ////SeoEDesc
            //model.SeoEDesc = txtSeoEDesc.Value;

            //排序
            model.OrderId = Convert.ToInt32(txtOrderId.Value);

            ////SiteID
            //model.SiteID = Convert.ToInt32(txtSiteID.Value);

            ////
            //model.ListTemplate = txtListTemplate.Value;

            ////
            //model.ListETemplate = txtListETemplate.Value;

            ////
            //model.ContentTemplate = txtContentTemplate.Value;

            ////
            //model.ContentETemplate = txtContentETemplate.Value;
            model.CreateUserId = model.CreateUserId == 0 ? AdminUser.Id : model.CreateUserId;
            if (CenterService.navService.Save(model) > 0)
            {

                JsHelper.CloseDialog(this, CommFunMsg.GetMessage("a0001", Lan.zh));
            }
            else {
                JsHelper.Alert(this, CommFunMsg.GetMessage("a0001", Lan.zh));
            
            }

        }

    }

}
 